package com.ctshk.rpc.season.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ctshk.rpc.season.dto.FixedSeasonProductCertificatesDTO;
import com.ctshk.rpc.season.dto.FixedSeasonProductPageDTO;
import com.ctshk.rpc.season.entity.SeasonFixedProduct;
import com.ctshk.rpc.season.entity.SeasonProductStrategy;
import com.ctshk.rpc.season.entity.SeasonProductStrategyVaildDate;
import com.ctshk.rpc.season.req.SearchFixedProductReq;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 套票-固定套票产品基本信息表 Mapper 接口
 * </p>
 *
 * @author 杨林
 * @since 2021-03-08
 */
public interface SeasonFixedProductMapper extends BaseMapper<SeasonFixedProduct> {


    /* @MethodName: 获取固定套票产品信息
     * @Description: TODO
     * @Param:
     * @Return:
     * @Author: 杨林
     * @Date:2021/3/11 17:31
     **/

    IPage<FixedSeasonProductPageDTO> searchSeasonFixedProduct(@Param("req") SearchFixedProductReq req, IPage<FixedSeasonProductPageDTO> page);



    /* @MethodName: 根据ids 获取套票信息
     * @Description: TODO
     * @Param:
     * @Return:
     * @Author: 杨林
     * @Date:2021/4/22 16:20
     **/


    @Select("<script> SELECT tp.id product_id,tp.product_name, tp.code, pp.id package_id,tp.subtitle,pp.season_type_name, \n" +
            "tp.travel_days,tp.dep_city_name,tp.arr_city_name,tp.travel_group,tp.kind,pp.season_type_id, \n" +
            "pp.package_product_flag,tp.applicable_crowd_name,tp.charge_user_id,tp.sell_status,tp.approval_status \n" +
            "FROM t_season_fixed_product tp JOIN t_season_fixed_product_package pp ON tp.id=pp.product_id \n" +
            "WHERE tp.is_deleted = 0  and tp.id in (${ids}) \n" +
            "</script>"
    )
    List<FixedSeasonProductPageDTO> getSeasonProductList(@Param("ids") String ids);


    int deleteBusByPackageId(@Param("packageId") Long packageId);

    int deleteLocalFunByPackageId(@Param("packageId") Long packageId);

    int deleteCommodityByPackageId(@Param("packageId") Long packageId);

    int deleteDepartDateByPackageId(@Param("packageId") Long packageId);


    //根据产品id  和日期获取 固定套票 策略信息
    List<SeasonProductStrategy> queryStrategyByProductIdDate(@Param("productId") Long productId, @Param("date") LocalDate date);


    //根据产品id  和日期获取 固定套票 策略信息
    List<SeasonProductStrategyVaildDate> queryStrategDateyByProductId(@Param("productId") Long productId, @Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate);

    @Select("<script> SELECT  tp.dep_city_id,tp.arr_city_id,pp.package_product_flag\n" +
            "FROM t_season_fixed_product tp JOIN t_season_fixed_product_package pp ON tp.id=pp.product_id \n" +
            "WHERE tp.is_deleted = 0 \n" +
            "</script>"
    )
    FixedSeasonProductCertificatesDTO getPackageProductByProductId(Long productId);

    @Update({
            "update t_season_fixed_product set cache_price = #{cachePrice} where id = #{productId}"
    })
    Integer updateCachePrice(@Param("productId") Long productId, @Param("cachePrice") BigDecimal cachePrice);
}
